package com.example.gss.ServiceImpl;

import com.example.gss.entity.SocialService;
import com.example.gss.mapper.SocialServiceMapper;
import com.example.gss.Service.SocialServiceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Optional;

@Service
public class SocialServiceServiceImpl implements SocialServiceService {

    @Autowired
    private SocialServiceMapper socialServiceMapper;

    @Override
    @Transactional
    public SocialService createService(SocialService service) {
        socialServiceMapper.insert(service);
        return service;
    }

    @Override
    public List<SocialService> getAllServices() {
        return socialServiceMapper.selectAll();
    }

    @Override
    public Optional<SocialService> getServiceById(String serviceId) {
        return Optional.ofNullable(socialServiceMapper.selectById(serviceId));
    }

    @Override
    @Transactional
    public SocialService updateService(SocialService service) {
        socialServiceMapper.update(service);
        return service;
    }

    @Override
    @Transactional
    public void deleteService(String serviceId) {
        socialServiceMapper.delete(serviceId);
    }

    @Override
    public List<SocialService> findServicesByStudentId(String studentId) {
        return socialServiceMapper.selectByStudentId(studentId);
    }

    @Override
    public List<SocialService> findServicesByType(String type) {
        return socialServiceMapper.selectByType(type);
    }
}